﻿function get_AdminType_Html(){
  var htmlstr='<table id="Grid_AdminType" style="width:auto;height:auto"></table><div id="addAdminTypediv" style="display:none"></div><div id="edtAdminTypediv" style="display:none"></div>';
  return htmlstr;
}
function getadd_AdminType_Html(){
  var htmlstr='<div id="AddDlg_AdminType" title="添加记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="380" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="100"> 权限级别名 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AdminTypeName" id="add_AdminTypeName" class="easyui-validatebox" required="true" /></td></tr>';
  htmlstr=htmlstr+'<tr><td> 权限列表 </td>';
  htmlstr=htmlstr+'<td><input id="add_tree_power" class="easyui-combotree" style="width:200px;" /></td></tr>';
  htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="addbt_AdminType" href="javascript:void(0)" onclick="Add_AdminType()"> 添 加 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function getedt_AdminType_Html(){
  var htmlstr='<div id="EditDlg_AdminType" title="修改记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="380" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td> 权限分类 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="edt_AdminTypeName" id="edt_AdminTypeName" class="easyui-validatebox" required="true" /></td></tr>';
  htmlstr=htmlstr+'<tr><td> 权限列表 </td>';
  htmlstr=htmlstr+'<td><input id="edt_tree_power" class="easyui-combotree" style="width:200px;" /></td></tr>';
  htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="edtbt_AdminType" href="javascript:void(0)" onclick="Edit_AdminType()"> 修 改 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function Add_AdminType_Tab(tabname){
  if(!$('#ttab').tabs('exists',tabname)){
	$('#ttab').tabs('add',{
		title:tabname,
		cache:false,
		closable:true,
		content:get_AdminType_Html()
	  });
	var gridht = $('body').layout('panel','center').panel('options').height - 58;
	$('#Grid_AdminType').datagrid({
	  border:false,
	  nowrap: false,
	  striped: true,
	  collapsible:true,
	  url:'/Data/AdminType.ashx',
	  method:'get',
	  height:gridht,
	  queryParams:{type:"0"},
	  fitColumns:true,
	  loadMsg:'正在读取数据,请稍候...',
	  singleSelect:true,
	  columns:[[
		{field:'AdminTypeId',checkbox:true},
		{field:'AdminTypeName',title:'权限分类',width:80}]],
	  pagination:true,
	  rownumbers:true,
	  toolbar:[{
		id:'btn_AdminType_add',
		text:'添加权限',
		iconCls:'icon-add',
		handler:function(){
		  ShowAdminTypeAddFrom();}
		},'-',{
		id:'btn_AdminType_edit',
		text:'修改权限',
		iconCls:'icon-edit',
		handler:function(){
		  GetOne_AdminType();}
		},'-',{
		id:'btn_AdminType_del',
		text:'删除权限',
		iconCls:'icon-remove',
		handler:function(){
		 Del_AdminType();}
	  }],
	  onLoadError:function(er){
		  $.messager.alert('错误','可能无查看权限,无法加载数据!','error');
	  }
	});
  }else{
	$('#ttab').tabs('select',tabname);
  }
}
function ShowAdminTypeAddFrom(){
  $('#addAdminTypediv').html(getadd_AdminType_Html());
  $.parser.parse($('#addAdminTypediv'));
  $('#AddDlg_AdminType').window({
	  title: '添加新管理权限',
	  width: 450,
	  modal: false,
	  shadow: false,
	  closed: true,
	  height: 200
  });
  $('#addbt_AdminType').linkbutton({iconCls:"icon-ok"});
  $('#add_tree_power').combotree({
	  checkbox: true,
	  multiple: 'true',
	  url: '/Data/AdminAction.ashx?type=2',
	  method:'get'
	  });
  $('#AddDlg_AdminType').window('open');
}
function ShowAdminTypeEdtFrom(){
  $('#edtAdminTypediv').html(getedt_AdminType_Html());
  $.parser.parse($('#edtAdminTypediv'));
  $('#edt_tree_power').combotree({
	  checkbox: true,
	  multiple: 'true',
	  url: '/Data/AdminAction.ashx?type=2',
	  method:'get'
	  });
}
function Add_AdminType(){
  var vall = $('#add_tree_power').combotree('tree');
  var nodes = vall.tree('getChecked');
  var s = '';
  for(var i=0; i<nodes.length; i++){
	  if (nodes[i].attributes){
		  if (s != '') s += ',';
		  s += nodes[i].attributes.func;
	  }
  }
  var atname=$('#add_AdminTypeName').val();
  if(atname==''){
	  $.messager.show({
				title:'提示',
				msg:'没有输入权限名.',
				timeout:3000,
				showType:'slide'
			});
	  return;
  }
  $.get("/Data/AdminType.ashx",{type:2,AdminTypeName:atname,AdminPowerList:s},
  function(data){
    $('#AddDlg_AdminType').window('close');
	$('#Grid_AdminType').datagrid("reload");
  });
}
function GetOne_AdminType(){
  var getid=0;
  var selected = $('#Grid_AdminType').datagrid('getSelected');
  if (selected){
    getid=selected.AdminTypeId;
	$.getJSON("/Data/AdminType.ashx",{type:1,id:getid},
	function(data){
			ShowAdminTypeEdtFrom();
			$('#EditDlg_AdminType').window({
				title: '修改管理权限',
				width: 450,
				modal: true,
				shadow: true,
				closed: true,
				height: 200
				});
			$('#EditDlg_AdminType').window('open');
			$('#edtbt_AdminType').linkbutton({iconCls:"icon-ok"});
						$('#edt_AdminTypeId').val(data.model.AdminTypeId);
						$('#edt_AdminTypeName').val(data.model.AdminTypeName);
						$('#edt_AdminPowerList').val(data.model.AdminPowerList);
			
      });
	}else{
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
	}
}
function Edit_AdminType(){
  var vall = $('#edt_tree_power').combotree('tree');
  var nodes = vall.tree('getChecked');
  var s = '';
   var getid=0;
  for(var i=0; i<nodes.length; i++){
	  if (nodes[i].attributes){
		  if (s != '') s += ',';
		  s += nodes[i].attributes.func;
	  }
  }
  var selected = $('#Grid_AdminType').datagrid('getSelected');
  getid=selected.AdminTypeId;
  $.get("/Data/AdminType.ashx",{type:4,id:getid,AdminTypeName:$('#edt_AdminTypeName').val(),AdminPowerList:s},
  function(data){
    $('#EditDlg_AdminType').window('close');
	$('#Grid_AdminType').datagrid("reload");
  }); 
}
function Del_AdminType(){
  var getid=0;
  var selected = $('#Grid_AdminType').datagrid('getSelected');
  if(!selected){
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
			return;
  }
  
  getid=selected.AdminTypeId;
  $.messager.confirm('确认删除', '请确认是否进行此操作?', function(r){
	  if(r){
			$.get("/Data/AdminType.ashx",{type:3,id:getid},
			function(data){
				$.messager.show({
					title:'提示',
					msg:'已删除数据.',
					timeout:3000,
					showType:'slide'
				});
				$('#Grid_AdminType').datagrid("reload");
			}); 
		  }
  }); 
} 
  